@isTest
public class ReturnOrderListControllerTest
{
    static testMethod void ReturnOrderListControllerTest()
    {
        ///创建 客户
        
        Account acc = TestUtils.createAccount();
        acc.Level__c = '一级医院';
        insert acc ;
        
        //创建产品
         Product__c p1 = TestUtils.createProduct();
        insert p1;
        Product__c p2 = TestUtils.createProduct();
        insert p2;
        Product__c p3 = TestUtils.createProduct();
        insert p3;
        

        //新建退货通知单
        ReturnRequisition__c rr  = new ReturnRequisition__c();
        rr.Account__c = acc.Id;
        insert rr; 

        ReturnRequisitionList__c rrL = new ReturnRequisitionList__c();
        rrL.ReturnRequisition__c = rr.Id ; 
        rrL.Product__c = p3.Id;
        insert rrL;


        PageReference page1= new PageReference('/apex/ReturnOrderList?id=' + rr.Id );
        System.Test.setCurrentPage(page1);

        ReturnOrderListController roc1 = new ReturnOrderListController();
        roc1.init();

        roc1.saveJson  = EncodingUtil.urlEncode('[{"dbilldate":"2018-12-11","corpcode":"MKSY","dbillcode":"XC02181240020","invcode":"110100100025","vbatchcode":"0718071","nnum":10,"dproducedate":"2018-07-18","dr":0,"invpinpai":"迈克生物","invname":"天门冬氨酸氨基转移酶测定试剂盒（天门冬氨酸底物法）","vdotechnics":"2022-02-15","custname":"广安市人民医院","vapprovalnum":"川械注准20172400051","custcode":"604479","invdm":"CH0101202","dvalidate":"2020-07-18","zdkh":"广安市人民医院","nshouldoutnum":10,"jldw":"盒","invtype":"AST：7170双","invspec":"试剂1 60mL×3 试剂2 45mL×1"}]', 'UTF-8');
        roc1.save();



        
        
        //创建退货申请
        ReturnOrder__c  ro = new ReturnOrder__c(
            Account__c = acc.Id
            
        );
        insert ro;
        //创建退货申请明细
        ReturnOrderList__c  rol = new ReturnOrderList__c(
            Product__c = p3.Id,
            ReturnOrderList__c = ro.Id
            

        );
        insert rol;
        
        PageReference page = new PageReference('/apex/ReturnOrderList?id=' + ro.Id+'&type=new' );
        System.Test.setCurrentPage(page);
        ReturnOrderListController roc = new ReturnOrderListController();
        roc.init();
        roc.getReturnList();
        roc.searchJson = EncodingUtil.urlEncode('{"invcode":"111","invname":""}', 'UTF-8');
        roc.search();
       
        
        roc.saveJson  = EncodingUtil.urlEncode('[{"dbilldate":"2018-12-11","corpcode":"MKSY","dbillcode":"XC02181240020","invcode":"110100100025","vbatchcode":"0718071","nnum":10,"dproducedate":"2018-07-18","dr":0,"invpinpai":"迈克生物","invname":"天门冬氨酸氨基转移酶测定试剂盒（天门冬氨酸底物法）","vdotechnics":"2022-02-15","custname":"广安市人民医院","vapprovalnum":"川械注准20172400051","custcode":"604479","invdm":"CH0101202","dvalidate":"2020-07-18","zdkh":"广安市人民医院","nshouldoutnum":10,"jldw":"盒","invtype":"AST：7170双","invspec":"试剂1 60mL×3 试剂2 45mL×1"}]', 'UTF-8');
        roc.save();
        
       List<ReturnOrderList__c> rolList = [select Id from ReturnOrderList__c where ReturnOrderList__c =:ro.Id];


       ReturnRequisitionList__c  rll1 = [select Id from ReturnRequisitionList__c where ReturnRequisition__c=:rr.Id  limit 1 ];
       ReturnOrderList__c rol1 = [select Id from ReturnOrderList__c where ReturnOrderList__c=:ro.Id  limit 1 ];
       rol1.ReturnRequisitionList__c = rll1.Id;
       update rol1 ;

       ro.Done__c = true;
       ro.NCreturnNumber__c = 'XC02181240020';
       update ro ; 

       if(rolList.size()> 0) delete rolList;







        
        
    }
}